package com.example.demo.Service.impl;

import com.example.demo.Service.RedisService;
import com.example.demo.util.RedisKeyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisServiceImpl implements RedisService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void savelike(Integer uid, Integer qid) {
        String key= RedisKeyUtils.getLikedKey(uid.toString(),qid.toString());
        redisTemplate.opsForHash().put(RedisKeyUtils.MAP_KEY_USER_LIKED,key,1);
    }

    @Override
    public void savedislike(Integer uid, Integer qid) {
        String key= RedisKeyUtils.getLikedKey(uid.toString(),qid.toString());
        redisTemplate.opsForHash().put(RedisKeyUtils.MAP_KEY_USER_LIKED,key,0);
    }

    @Override
    public void countup(Integer qid) {
        redisTemplate.opsForHash().increment(RedisKeyUtils.MAP_KEY_USER_LIKED_COUNT,qid,1);
    }

    @Override
    public void countdown(Integer qid) {
        redisTemplate.opsForHash().increment(RedisKeyUtils.MAP_KEY_USER_LIKED_COUNT,qid,-1);

    }
}
